package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Order;
import com.itheima.reggie.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/order")
public class OrderController {

    //依赖注入
    @Autowired
    private OrderService orderService;

    /**
     * 查询订单列表 + 模糊查询 + 时间查询
     * Request URL: http://localhost:8080/order/page?page=1&pageSize=10&number=1
     *              &beginTime=2022-06-29%2000%3A00%3A00&endTime=2022-07-25%2023%3A59%3A59
     * Request Method: GET
     */
    @GetMapping("/page")
    public ResultInfo findList(@RequestParam(name = "page",defaultValue = "pageNum") Integer pageNum,
                               @RequestParam(name = "pageSize",defaultValue = "pageSize") Integer pageSize,
                               String number,
                               @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date beginTime,
                               @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date endTime){   //接收分页参数 和 普通参数
        //1.调用service层
        Page<Order> page = orderService.findList(pageNum,pageSize,number,beginTime,endTime);
        //2.返回响应
        return ResultInfo.success(page);
    }
}
